//
//  BPWiFiViewController.m
//  BPTV
//
//  Created by baipeng on 2018/11/16.
//  Copyright © 2018年 Apple Inc. All rights reserved.
//

#import "BPWiFiViewController.h"
#import "BPWiFiUploadManager.h"
#import "BPWiFiView.h"
@interface BPWiFiViewController ()
@property (nonatomic, weak) BPWiFiView *wifiView;

@end

@implementation BPWiFiViewController

#pragma mark - life cyle 1、控制器生命周期
- (void)loadView {
    BPWiFiView *wifiView = [[BPWiFiView alloc]init];
    self.wifiView = wifiView;
    self.view = wifiView;
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    BPWiFiUploadManager *manager = [BPWiFiUploadManager shareInstance];
    HTTPServer *server = manager.httpServer;
    if (server.isRunning) {
        if ([BPIPHelper deviceIPAdress] == nil) {
            [self.wifiView setAddress:@"Error, your Device is not connected to WiFi"];
            return;
        }
        NSString *ip_port = [NSString stringWithFormat:@"http://%@:%@",manager.ip,@(manager.port)];
        [self.wifiView setAddress:ip_port];
    }else{
        [self.wifiView setAddress:@"Error, Server Stopped"];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"WiFi";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];

}
#pragma mark - 2、不同业务处理之间的方法以

#pragma mark - Network 3、网络请求

#pragma mark - Action Event 4、响应事件
-(void)dismiss{
    [self dismissViewControllerAnimated:YES completion:nil];
    if (self.dismissBlock) {
        self.dismissBlock();
    }
}
#pragma mark - Call back 5、回调事件

#pragma mark - Delegate 6、代理、数据源

#pragma mark - interface 7、UI处理

#pragma mark - lazy loading 8、懒加载


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
